package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbDynamic;
import com.ruoyi.system.service.ITbDynamicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 动态Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/dynamic")
public class TbDynamicController extends BaseController
{
    @Autowired
    private ITbDynamicService tbDynamicService;

    /**
     * 查询动态列表
     */
    @PreAuthorize("@ss.hasPermi('system:dynamic:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDynamic tbDynamic)
    {
        startPage();
        List<TbDynamic> list = tbDynamicService.selectTbDynamicList(tbDynamic);
        return getDataTable(list);
    }

    /**
     * 导出动态列表
     */
    @PreAuthorize("@ss.hasPermi('system:dynamic:export')")
    @Log(title = "动态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDynamic tbDynamic)
    {
        List<TbDynamic> list = tbDynamicService.selectTbDynamicList(tbDynamic);
        ExcelUtil<TbDynamic> util = new ExcelUtil<TbDynamic>(TbDynamic.class);
        util.exportExcel(response, list, "动态数据");
    }

    /**
     * 获取动态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dynamic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbDynamicService.selectTbDynamicById(id));
    }

    /**
     * 新增动态
     */
    @PreAuthorize("@ss.hasPermi('system:dynamic:add')")
    @Log(title = "动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDynamic tbDynamic)
    {
        return toAjax(tbDynamicService.insertTbDynamic(tbDynamic));
    }

    /**
     * 修改动态
     */
    @PreAuthorize("@ss.hasPermi('system:dynamic:edit')")
    @Log(title = "动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDynamic tbDynamic)
    {
        return toAjax(tbDynamicService.updateTbDynamic(tbDynamic));
    }

    /**
     * 删除动态
     */
    @PreAuthorize("@ss.hasPermi('system:dynamic:remove')")
    @Log(title = "动态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbDynamicService.deleteTbDynamicByIds(ids));
    }
}
